import java.util.Scanner;

public class 体操队形 {
    /*
    https://ac.nowcoder.com/acm/problem/229386
    观察数据范围, n的范围最大是10, 大概率是dfs
     */
    public static int n;
    public static int[] arr;
    public static boolean[] vis;

    public static int ret;

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        arr = new int[n + 1];
        vis = new boolean[n + 1];
        ret = 0;
        for (int i = 1; i <= n; i++) {
            arr[i] = in.nextInt();
        }
        //统计层数, 其他直接全局变量即可
        dfs(0);
        System.out.println(ret);
    }

    private static void dfs(int pos) {
        if(pos == n){
            ret++;
            return;
        }
        //枚举所有情况
        for (int i = 1; i <= n; i++) {
            //如果这个数被选过了就继续
            if(vis[i]){
                continue;
            }
            //由于i要排在arr[i]的前面, 所以如果要满足, 说明arr[i]此时没有被排过, 排过说明怎么样都不会满足直接return
            if(vis[arr[i]]){
                return;
            }
            //回溯加递归
            vis[i] = true;
            dfs(pos + 1);
            vis[i] = false;
        }
    }
}
